package com.cndw.kungfu.model.goods.app;

import java.util.HashMap;
import java.util.Map;

import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.exception.ErrPopException;
import com.cndw.kungfu.ext.LanguageLib;

/**
 * 物品使用的基类
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-9-8 下午7:44:24
 */
abstract class AppBase implements AppDo {
	/**
	 * 角色id
	 */
	protected long playerId;
	/**
	 * 使用者对象
	 */
	protected Player player;
	/**
	 * 物品id
	 */
	protected int goodsId;
	/**
	 * 物品模型
	 */
	protected GoodsMode goodsMode;
	/**
	 * 使用数量
	 */
	protected int num;
	/**
	 * 日誌文字
	 */
	protected String logString;
	/**
	 * 提示文字
	 */
	protected String ticpString;

	protected Map<String, Object> msg = new HashMap<String, Object>();

	abstract public boolean check() throws Exception;

	abstract public Map<String, Object> run() throws Exception;

	public void initApp(Player player, GoodsMode goodsMode, int num) {
		playerId = player.getPlayerId();
		this.player = player;
		goodsId = goodsMode.getGoodsId();
		this.goodsMode = goodsMode;
		this.num = num;
	}

	public void checkBlack(int black) throws Exception {
		if (player.getPlayerBoxs().checkBlack(black) == false) {
			throw new ErrPopException(LanguageLib.get("comm.player.boxmin", black));
		}

	}

	public String getLogString() {
		if (logString == null) {
			return "";
		}
		return logString;
	}

	public String getTicpString() {
		return ticpString;
	}

}
